package com.senriot.quickup.web.rest.wx

import com.senriot.quickup.domain.WxUserInfo
import com.senriot.quickup.service.WxService
import com.senriot.quickup.service.dto.UserDTO
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import me.chanjar.weixin.common.bean.WxJsapiSignature
import me.chanjar.weixin.mp.api.WxMpService
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/wx")
@Api(tags = ["微信"])
class WxResource(private val wxService: WxService, private val wxMpService: WxMpService)
{
    private val log = LoggerFactory.getLogger(this.javaClass)


    /**
     * 获取微信openId
     * @param code String
     * @return ScopeAccessToken?
     */
    @GetMapping("openid")
    @ApiOperation("获取微信openId")
    fun getWxOpenId(code: String, isPay: Boolean): WxUserInfo = wxService.getWxOpenId(code, isPay)

    @GetMapping("wx-config")
    @ApiOperation(value = "获取微信js-sdk配置")
    fun getWxConfig(url: String): WxJsapiSignature = wxMpService.createJsapiSignature(url)

    @PostMapping("reseller-signup")
    @ApiOperation(value = "微信注册经销商")
    fun resellerSignup(@RequestBody dto: UserDTO) = wxService.resellerSignup(dto)


    @GetMapping("reseller-status")
    @ApiOperation(value = "经销商状态")
    fun checkReseller(openId: String) = wxService.checkReseller(openId)
}
